package com.charles.seckillFile.service.impl;

import com.charles.seckillFile.service.FileUploadService;
import com.charles.seckillFile.utils.FileTypeUtils;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FastFileUploadServiceImpl implements FileUploadService {

    @Value("${file.domain}")
    public String domain;
    
    @Autowired
    private FastFileStorageClient fastFileStorageClient;
    
    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(),
                FileTypeUtils.getExtension(file), null);
        return domain + "/" + storePath.getFullPath();
    }
}
